<link href="/theme/Default/css/shopCategory/index.css" rel="stylesheet">
<form action="/ShopCategories/edit" method="post" id="shopCategories">
	<div id="shopCategories">
		<div class="shopCategories_header">
			Chọn danh mục trong gian hàng<span class="posting_notice">(Vui lòng chọn danh mục )</span>
		</div>
		<div class="shopCategories_content">
			 <?php
			 	$n = 0;
			    foreach ($rootCategories as $item){?>
					<div class="root_cat_name"> <?php echo $item['RootCategory']['category_name']?></div>
					<input type="hidden" name="data[<?php echo $n; ?>][root_cat]" value="<?php echo $item['RootCategory']['id']?> " />
					<?php
					$i = 0;
					$j = 0;
					foreach ($item['Category'] as $cat){?>
						<label class="checkbox-inline ckbox_cat">
							<input type="checkbox" value="<?php echo $cat['category_id']?>" name="data[<?php echo $n; ?>][shopCat][<?php echo $j; ?>]"/><?php echo $cat['category_name']?>
						</label>
					<?php
						if($i == 3){
							echo "<br>";
							$i = 0;
						}else{
							$i++;	
						}
						$j++;
						
					}
					$n++;
			    }
			?>
		</div>
		<div class="shopCategories_footer">
			<button type="submit" class="btn btn-danger btn_submit">Cập nhật</button>
		</div>
	</div>
	<?php
		$strCatId = "";
		foreach ($shopCat as $item) {
			foreach ($item['shopCat'] as $i) {
				$strCatId = $strCatId . $i['catId'] . ",";
			}
		}
	?>
	<!-- <input type="hidden" name="data[strCatId]" value="<?php echo $strCatId;?>"/> -->
</form>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">Thông báo</h4>
      </div>
      <div class="modal-body">
       
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" data-dismiss="modal">Đóng</button>
        <!-- <button type="button" class="btn btn-primary">Save changes</button> -->
      </div>
    </div>
  </div>
</div>
<script>
	$(document).ready(function() {
		var strCatId = "<?php echo $strCatId; ?>";
		strCatId = strCatId.substring(0, strCatId.length - 1);
		var arrId = strCatId.split(',');
		n = arrId.length;
		for (i = 0; i < n; i++){
			$("input[type='checkbox'][value='"+arrId[i]+"']").prop("checked", true);
		}
		$(".btn_submit").click(function(){
			var n = $("input[type='checkbox']:checked").size();
			if(n == 0){
				showPopupMessage('#myModal',"Chọn ít nhất 1 danh mục");
				return false;
			}
			return true;
		});
	});
	function showPopupMessage(idModal, msg){
		$(idModal).find('.modal-body').html(msg);
		$(idModal).modal('show');
	}
</script>